﻿Public Class ContactUs
    Inherits System.Web.UI.Page

    Public ConnectionString As String = ConfigurationManager.AppSettings("ConnectionString").ToString
    Public objData As New DatabaseClass(ConnectionString)
    Public objDataRead As New DatabaseClass(ConnectionString)
    Public objFunction As New FunctionClass
    Public objAlert As New AlertClass
    Public objConfig As New Configs
    Dim Sql As String = ""

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            loadData()
        End If
    End Sub

    ' Kiem tra du lieu va load data cua khach hang
    Public Sub loadData()
        Try
            ' Kiem tra xem dang nhap chua, neu khong co redirect ve trang chu
            If (Session("CusUserName") <> Nothing) Or (Session("CusUserName") <> "") Or (Session("CusFullname") <> Nothing) Or (Session("CusFullname") <> "") Then
                txtName.Text = Session("CusFullname")
                txtEmail.Text = Session("CusEmail")
            End If
        Catch ex As Exception
        End Try
    End Sub

    Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Try
            Sql = "spo_ContactUsInsert "
            Sql &= objFunction.FieldUniCk(txtName.Text) & ","
            Sql &= objFunction.FieldCheck(txtEmail.Text) & ","
            Sql &= objFunction.FieldUniCk(txtContent.Text)
            objDataRead.ExeNonQuery(Sql)
            objAlert.InfoBox(Page, "Cám ơn bạn đã gửi thông tin tới chúng tôi. Chúng tôi sẽ phản hồi lại bạn sớm nhất có thể", "/")
        Catch ex As Exception
            If objConfig.Developer.Equals("1") Then
                objAlert.ErrorBox(Page, "File: " & (New System.Diagnostics.StackTrace).GetFrame(0).GetMethod.DeclaringType.Name & _
                                  " --- Function: " & (New System.Diagnostics.StackTrace).GetFrame(0).GetMethod.Name & _
                                  " --- Mess: " & ex.Message.Replace("'", """"))
            Else
                objAlert.ErrorBox(Page, "Lỗi kỹ thuật, hãy thông báo lại với Admin, xin cảm ơn.")
            End If
        End Try
    End Sub
End Class